package com.yrd.common.handler;

public class HandlerThread extends Thread{
	Looper looper;
	
	public HandlerThread(String name) {
		super(name);
	}
	
	@Override
	public void run() {
		Looper.prepare();
		synchronized (this) {
			looper = Looper.myLooper();
            notifyAll();
        }
		looper.loop();
	}

	public synchronized Looper getLooper() {
		if(!isAlive()){
			return null;
		}else if(isAlive() && looper==null){
			try {
                wait();
            } catch (InterruptedException e) {}
		}
		return looper;
	}
	
	public void quit(){
		Looper looper = getLooper();
        if (looper != null) {
            looper.quit();
        }
	}
	
}
